package com.gp.testonline.controller;

import com.gp.testonline.eo.LoginlogEOPage;
import com.gp.testonline.model.Loginlog;
import com.gp.testonline.service.LoginlogService;
import com.gp.testonline.tool.ResponseMessage;
import com.gp.testonline.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据服务接口
 */
@Api(tags = "loginlog")
@RestController
public class LoginlogController {
    @Autowired
    private LoginlogService loginlogService;

    @ApiOperation(value = "添加日志信息")
    @RequestMapping(value = "/insertLoginlog",method = RequestMethod.GET)
    public ResponseMessage insertLoginlog(Loginlog loginlog){
        int isInsert=0;
        //传入的参数不能为空
        if(loginlog!=null){
            //参数当中主键不能为0
            if (loginlog.getLid()!=0){
                isInsert=loginlogService.InsertLoginlog(loginlog);
                if (isInsert==1){
                    return Result.success("添加成功！");
                }else {
                    return Result.error("添加失败！");
                }
            }else {
                return Result.error("传入的参数不正确");
            }
        }
        return Result.error("传入的参数不正确");
    }

    @ApiOperation(value = "根据条件获取日志信息")
    @RequestMapping(value = "/getLoginlog",produces = "application/json;charest=utf-8",method = RequestMethod.PUT)
    public ResponseMessage getLoginlog( LoginlogEOPage loginlogEOPage){
        Map<String, List> map=new HashMap<>();
        List<LoginlogEOPage> listLoginlog=loginlogService.getLoginlogAll(loginlogEOPage);
        map.put("list",listLoginlog);
        return Result.success("200",map);
    }
}
